package com.kexinde.wjifen.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.RequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.kexinde.wjifen.model.ConsumptionRecord;
import com.kexinde.wjifen.model.NormalUser;
import com.kexinde.wjifen.model.Shop;
import com.kexinde.wjifen.model.Worker;
import com.kexinde.wjifen.service.IConsumptionRecordManager;
import com.opensymphony.xwork2.ActionSupport;
@Component("ConsumptionRecord")
@Scope("prototype")
public class ConsumptionRecordAction extends ActionSupport implements
		RequestAware {
	/**
	 * 查询积分汇总信息
	 */
	private ConsumptionRecord consumptionRecord;
	private IConsumptionRecordManager consumptionRecordManager;
	private Map<String, Object> request;
	private Shop shop;
	private NormalUser normalUser;
	private Worker worker;
	private int point;

	public String showShopAllConsumptionRecords() { // 显示店铺所有会员消费记录
		List<ConsumptionRecord> consumptionRecords = this.consumptionRecordManager
				.showShopAllConsumptionRecords(shop.getId());
		request.put("consumptionRecords", consumptionRecords);
		return SUCCESS;
	}

	public String showShopPersonalConsumptionRecords() { // 显示店铺个人会员消费记录
		List<ConsumptionRecord> consumptionRecords = this.consumptionRecordManager
				.showShopPersonalConsumptionRecord(shop.getId(), normalUser.getUserName());
		request.put("consumptionRecords", consumptionRecords);
		return SUCCESS;
	}

	public String showPersonalAllConsumptionRecords() { // 显示会员个人所有消费记录
		List<ConsumptionRecord> consumptionRecords = this.consumptionRecordManager
				.showPersonalAllConsumptionRecords(normalUser.getUserName());
		request.put("consumptionRecords", consumptionRecords);
		return SUCCESS;
	}

	public String add() { // 增加消费记录
		if (this.consumptionRecordManager.add(worker.getUserName(), normalUser.getPhone(), point))
			return SUCCESS;
		else
			return ERROR;
	}

	public String modify() { // 修改消费记录
		if (this.consumptionRecordManager.modify(consumptionRecord))
			return SUCCESS;
		else
			return ERROR;
	}

	public String delete() { // 删除消费记录
		if (this.consumptionRecordManager.delete(consumptionRecord))
			return SUCCESS;
		else
			return ERROR;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		// TODO Auto-generated method stub
		this.request = request;
	}

	public ConsumptionRecord getConsumptionRecord() {
		return consumptionRecord;
	}

	public void setConsumptionRecord(ConsumptionRecord consumptionRecord) {
		this.consumptionRecord = consumptionRecord;
	}

	public IConsumptionRecordManager getConsumptionRecordManager() {
		return consumptionRecordManager;
	}

	@Resource
	public void setConsumptionRecordManager(
			IConsumptionRecordManager consumptionRecordManager) {
		this.consumptionRecordManager = consumptionRecordManager;
	}

	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	public NormalUser getNormalUser() {
		return normalUser;
	}

	public void setNormalUser(NormalUser normalUser) {
		this.normalUser = normalUser;
	}

	public Worker getWorker() {
		return worker;
	}

	public void setWorker(Worker worker) {
		this.worker = worker;
	}

	public int getPoint() {
		return point;
	}

	public void setPoint(int point) {
		this.point = point;
	}
}
